package com.kexuexiong.mybatisplus;


import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.IDatabaseQuery;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.sun.org.apache.bcel.internal.generic.NEW;

import java.sql.SQLException;


public class MybatisPlusApplication {

    /**
     * 数据源配置
     */
    private static final DataSourceConfig DATA_SOURCE_CONFIG = new DataSourceConfig
            .Builder("jdbc:mysql://localhost:3306/freshfruit?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai", "root", "")
            .build();
    private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG_BUILDER = new DataSourceConfig
            .Builder("jdbc:mysql://localhost:3306/freshfruit?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai", "root", "");

    /**
     * 执行 run
     */
    public static void main(String[] args) throws SQLException {

        AutoGenerator generator = new AutoGenerator(DATA_SOURCE_CONFIG);
        generator.strategy(strategyConfig()
                .enableCapitalMode().enableSkipView()
                .entityBuilder().formatFileName("%sPO").enableLombok().enableColumnConstant()
                .enableTableFieldAnnotation()
                .mapperBuilder().formatMapperFileName("%sMapper").formatXmlFileName("%sXml")
                .controllerBuilder().formatFileName("%sController")
                .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImp")
                .build());
        generator.global(globalConfig().build());
        generator.packageInfo(packageConfig());
        generator.execute();
    }

    /**
     * 全局配置
     */
    private static GlobalConfig.Builder globalConfig() {
        return new GlobalConfig.Builder().fileOverride().author("xy").outputDir("D:\\temp");
    }

    /**
     * 包配置
     *
     * @return
     */
    private static PackageConfig packageConfig() {
        return new PackageConfig.Builder().parent("com.kexuexiong").build();
    }

    /**
     * 策略配置
     */
    private static StrategyConfig.Builder strategyConfig() {
        // 设置需要生成的表名
        return new StrategyConfig.Builder().addInclude("test");
    }
}
